function isEmpty(obj) {
	if (obj == null || obj == undefined || jQuery.trim(obj).length == 0 || obj == "" || obj === "null") {
		return true;
	}
	return false;
} 

/**
 * 验证传入值
 * 
 * @author Wangyu
 * @param str
 *            input value
 * @param min
 *            min length
 * @param max
 *            max length
 * @param type
 *            (只含有下面说明的) 
 *            0代表含有数字 
 *            a代表含有小写字母 
 *            A代表含有大写字母 
 *            _代表含有下划线
 *            E或e代表邮箱验证
 *            C表示中文
 * @return true:正确 false:错误
 */
function validateInput(str, min, max, type) {
	if (isEmpty(str)) {
		return false;
	}
	if (min && !isEmpty(min) && max && !isEmpty(max)) {
		var len = jQuery.trim(str).length;
		if (len < min || len > max) {
			return false;
		}
	}
	var vali = "/^[";
	if (type.indexOf("0") != -1) {
		vali += "0-9";
	}
	if (type.indexOf("a") != -1) {
		vali += "a-z";
	}
	if (type.indexOf("A") != -1) {
		vali += "A-Z";
	}
	if(type.indexOf("C") != -1){
		vali +="\u4E00-\u9FA5\uF900-\uFA2D";
	}
	if (type.indexOf("_") != -1) {
		vali += "_";
	}
	vali += "]{"+min+","+max+"}";
	vali += "$/";
	if (type == "e" || type == "E" ) {
		vali = "/^([a-zA-Z0-9_\-]+)@([a-zA-Z0-9_\-])+((\.[a-zA-Z0-9_\-]{2,3}){1,2})$/";
	}
	var patrn = eval(vali);
	if (!patrn.exec(str))
		return false;
	return true;
}

var CHECK = {
		"isEmail": checkEmail,
		"isPassword": checkPassword,
		"isNumber": checkNumber,
		"isEmpty": isEmpty,
		"isPic": checkPicture
};

/**
 * 各种验证的验证 
 */
function checkEmail(email) {
	var min = "", max = "", type = "E";
	return validateInput(email, min, max,type);
}

function checkPassword(password) {
	var min = 6, max = "", type = "0aA";
	return validateInput(password, min, max,type);
}

function checkNumber(number) {
	var min = 1, max = 3, type = "0";
	return validateInput(number, min, max,type);
}

function changeScript(str) {
	var reg = new RegExp("<.*?script[^>]*?>.*?(<\/.*?script.*?>)*","ig");
	return str.replace(reg, "");
}

function checkPicture(str) {
	if (isEmpty(str)) {
		return false;
	}
	var types = [".gif", ".jpg", ".jpeg", ".png", ".bmp"];
	var num = 0;
	for (var i = 0; i < types.length; i++) {
		var allow = types[i];
		if (str.indexOf(allow) != -1) {
			++ num;
		}
	}
	if (num == 1) {
		return true;
	}
	
	return false;
}

/**
 * 时间处理
 */
Date.prototype.format = function(format){ 
	var o = { 
			"M+" : this.getMonth()+1, //month 
			"d+" : this.getDate(), //day 
			"h+" : this.getHours(), //hour 
			"m+" : this.getMinutes(), //minute 
			"s+" : this.getSeconds(), //second 
			"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
			"S" : this.getMilliseconds() //millisecond 
	};

	if(/(y+)/.test(format)) { 
		format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 

	for(var k in o) { 
		if(new RegExp("("+ k +")").test(format)) { 
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
		} 
	} 
	
	return format; 
};